package com.captcha.mybatisdemo.mapper;

import com.captcha.mybatisdemo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Select("select * from userinfo")
    List<UserInfo> queryUserInfo();


    @Select("select * from userinfo where gender = #{gender} and delete_flag = #{delete_flag}")
    UserInfo queryUserInfo1(@Param("gender") Integer g, Integer delete_flag);


    @Select("select * from userinfo where gender = #{gender}")
    UserInfo queryUserInfo2(Integer gender);


    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo (username, password, age, gender) values " +
            "(#{userInfo.username},#{userInfo.password},#{userInfo.age},#{userInfo.gender})")
    Integer insert(@Param("userInfo") UserInfo userInfo);


    @Delete("delete from userinfo where id = #{id}")
    Integer delete(Integer id);

    @Update("<script>" +
            "update userinfo " +
            "<set>" +
            "<if test='username!=null'>username=#{username},</if>" +
            "<if test='age!=null'>age=#{age},</if>" +
            "</set>" +
            "where id=#{id}" +
            "</script>")
    Integer update(UserInfo userInfo);

    @Select("select id, username, `password`, age, gender, phone, " +
            "delete_flag as deleteFlag, create_time as createTime, update_time as updateTime from userinfo")
    List<UserInfo> select();


    @Results(id = "1", value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
    })
    @Select("select * from userinfo")
    List<UserInfo> select1();

    @ResultMap("1")
    @Select("select * from userinfo")
    List<UserInfo> select222();

}
